package dealhandler;

import java.util.Map;
import java.util.Set;

import io.netty.handler.codec.http.FullHttpRequest;

/**
 * http响应类，各种接口响应Controller
 * 
 * @author KK
 *
 */
public class ControllerAider {

	public static String dealUrlErro(String url, FullHttpRequest msg, Map<String, String> datas) {
		String sendMsg = "<html><body><h1>404</h1></body></html>";
		return sendMsg;
	}

	public static String dealUrldefault(String url, FullHttpRequest msg, Map<String, String> datas) {
		String sendMsg = "{Hello:Netty HTTP Server}";
		return sendMsg;
	}

	public static String dealUrlhi(String url, FullHttpRequest msg, Map<String, String> datas) {
		String sendMsg = "<html><body><h3>Netty HTTP Server</h3><p>Welcome to <a href=\"https://waylau.com\">waylau.com</a>!</p></body></html>";
		return sendMsg;
	}

	public static String dealUrllove(String url, FullHttpRequest msg, Map<String, String> datas) {
		String sendMsg = "<html><body><h3>Netty HTTP Server</h3><p>I Love You!赵楷</p></body></html>";
		return sendMsg;
	}

	public static String dealUrlGetTest(String url, FullHttpRequest msg, Map<String, String> datas) {
		String method = msg.method().name().toUpperCase();
		if (method.equals("GET")) {
			System.out.println("GET Values:");
			Set<String> keys = datas.keySet();
			for (String key : keys) {
				System.out.println("Key:" + key + ",Value:" + datas.get(key));
			}
			return "<html><body><h3>Netty HTTP Server</h3><p>Get Test</p></body></html>";
		} else {
			return dealUrlErro(url, msg, datas);
		}
	}

	public static String dealUrlPostTest(String url, FullHttpRequest msg, Map<String, String> datas) {
		String method = msg.method().name().toUpperCase();
		if (method.equals("POST")) {
			System.out.println("POST Values:");
			Set<String> keys = datas.keySet();
			for (String key : keys) {
				System.out.println("Key:" + key + ",Value:" + datas.get(key));
			}
			String sendMsg = "<html><body><h3>Netty HTTP Server</h3><p>POST Test</p></body></html>";
			return sendMsg;
		} else {
			return dealUrlErro(url, msg, datas);
		}
	}

	public static String dealUrlHeadersTest(String url, FullHttpRequest msg, Map<String, String> datas) {
		for (String name : msg.headers().names()) {
			System.out.println(name + ": " + msg.headers().get(name));
		}
		String sendMsg = "<html><body><h3>Netty HTTP Server</h3><p>I Love You!</p></body></html>";
		return sendMsg;
	}
}
